Skip to content

fix(data-objectstack): uploadFile/uploadFiles upload through the storage service presigned flow - #38237

Merged
objectstack-fleet[bot] merged 7 commits into
mainfrom
claude/project-thread-ciejge
Nov 28, 2026
Merged

objectstack-fleet[bot] merged 7 commits into
mainfrom
claude/project-thread-ciejge

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Tesla · project thread
Fixes #38163
Clause-②: no
Metadata-protocol: none

Route taken: (a). uploadFile and uploadFiles now upload through the package's own presigned storage adapter, createObjectStackUploadAdapter. recordId maps to attachTo with scope attachments, and the adapter's result maps to FileUploadResult. The declared DataSource contract promises an upload that returns a stored file, and the storage service is the one upload route the standard server serves, so (a) keeps that promise and (b) would not. Two options cannot be mapped: fieldName and metadata. Neither presigned request carries them. Those two are refused before any request, in the (b) manner, with an error that names the supported path, so nothing is dropped silently. Neither method sends a request to /api/data/RESOURCE/upload any more.

Why refusing fieldName / metadata is not a narrowing (Clause-②: no stands): before this PR every call to either method failed. The standard server answers the old route 404 ENDPOINT_NOT_FOUND (405 with the version segment), whatever options were passed, so no caller had a working upload that carried those options. This PR removes no working behaviour. A call that always failed now succeeds without the two options, and with them it fails at once with an error that names the supported path, instead of a 404. The public types (DataSource.uploadFile / uploadFiles, FileUploadResult) are unchanged, and no metadata an author writes is affected (Metadata-protocol: none).

维护者速读

  • 用户能看到什么变化:用界面数据层「上传文件」接口的应用和插件,上传现在真正落到存储服务,拿回已存好的文件;以前每次都失败。普通控制台用户无感,因为仓库里没人调用它。
  • 为什么做:修复界面数据层对外声明却发往一条不存在地址的上传接口,替以后要调用它的应用解决问题。
  • 出错会怎样:调用方传了直传流程带不了的两个附加选项,会立刻收到写明改法的报错,而不是被悄悄丢掉。其余改动可直接撤回。
  • 要你做的:无。

What changes

  • ui/packages/data-objectstack/src/index.ts: uploadFile delegates to createObjectStackUploadAdapter, which sends POST /api/v1/storage/upload/presigned, the byte PUT, then POST /api/v1/storage/upload/complete. The adapter is built per call because attachTo is one of its construction options. The fetch it uses is built once per data source (storageUploadFetch). That fetch is the injected uploadTransport (data-objectstack:上传文件和 metadata-client 绕过注入的 fetch,纯令牌会话下被当匿名(接 #37225) #37506), plus the data source's token on every request to this server and never on a presigned URL on another origin. The same-origin check compares resolved origins: the URL is resolved against baseUrl, or the page's origin when baseUrl is empty, and it counts as this server only when the origins match (and, for a baseUrl with a path, the resolved path lies under it). A server that cannot be read, or a URL that does not parse, is not this server. uploadFiles is N sequential presigned uploads. The first refused file stops the batch, and the rejection's details carry failedIndex plus, as uploaded, the files already stored. The files after it are not sent.
  • Option mapping: recordId maps to attachTo: { parentObject: resource, parentId: recordId } and scope: 'attachments'. Without it, no scope is sent, so the server default applies, and resource is not sent. onProgress maps the adapter's 0 to 1 ratio to 0 to 100, spread across the batch for uploadFiles. fieldName and metadata reject with UNSUPPORTED_OPERATION before any request.
  • Errors: a refused storage request rejects ObjectStackError with UPLOAD_ERROR, the server's status, and details.serverCode. A failure that got no HTTP answer reaches the caller unchanged, as before.
  • ui/packages/data-objectstack/src/upload-adapter.ts: the presign refusal and the byte-PUT refusal now carry status (and code), as the completion refusal already did, so the mapping above can read them. Messages are unchanged.
  • No public shape changes: DataSource.uploadFile / uploadFiles and FileUploadResult are untouched.
  • packages/qa/dogfood/test/data-objectstack-upload-route-38163.dogfood.test.ts: the real-stack pin. packages/qa/dogfood/package.json gains one devDependency, @object-ui/data-objectstack (workspace:*), and pnpm-lock.yaml gains only that importer entry, written by pnpm install. With that, the pin resolves the adapter, the dogfood closure builds it, and the dogfood test hash follows adapter changes. packages/qa/dogfood/vitest.config.ts gains the one anchored alias check:test-source-alias prescribes, so the pin resolves the adapter's SOURCE in this checkout and not its last build. The dogfood package is private, so it needs no changeset.

Tests

  • uploadTransport-37506.test.ts is updated, because its fake server now answers 404 on /api/data/RESOURCE/upload as the real one does. The data-objectstack:上传文件和 metadata-client 绕过注入的 fetch,纯令牌会话下被当匿名(接 #37225) #37506 pins keep their meaning: injected fetch, bearer on every request, connection state unchanged. A new top-level describe for data-objectstack 的 uploadFile/uploadFiles 发往一条服务端不存在的路由,上传必然失败(404/405) #38163 checks that no request reaches the unserved route, the exact three-step sequence per file, the recordId mapping and result, the default scope without recordId, the refusal of fieldName and metadata with zero requests, token-only signing with no token on a foreign presigned URL, UPLOAD_ERROR code, status and serverCode, the partial-batch report, progress, and presigned URLs spelled protocol-relative (//host), slash-backslash and double-backslash getting no token while the presign and complete requests keep it. Ablation, run after the commit: with the previous string check restored, the slash-backslash case fails (1 of 15). The double-backslash case already got no token under that check. With the origin comparison removed, all three spellings and the cross-origin case fail (4 of 15). After restoring, git status is clean.
  • Unit ablation: with the base index.ts restored on disk, the file reported 12 of 12 failed. With the fix restored, it reported 21 of 21 passed (this file plus objectstack-upload-scope-12055.test.ts).
  • Package run: 128 of 128 test files and 1450 of 1450 tests passed, and type-check exited 0, both on 95e3f9f.
  • Real-stack pin (2 of 2 passing again on 95e3f9f; its baseUrl is a bare origin, so no path rule applies), first measured on head 9725c42, resolving the adapter source through the alias (the dependency is declared, and no link was made by hand). The stack is bootStack with StorageServicePlugin, the attachments fixture and a bearer-only session. uploadFile with a recordId (token only) and uploadFiles (host bearer fetch) pass 2 of 2. They assert committed sys_file rows, the sys_attachment row with its attachmentId, and that no request reached an unserved upload path. Ablation: with the base index.ts restored on disk (the file shows the old route twice), both tests fail with UPLOAD_ERROR "Not found", the server's 404. After git checkout HEAD, git status is clean and both pass again. The dogfood typecheck exits 0.

Acceptance notes

  • README.md (File Uploads) does not describe uploadFile / uploadFiles, and it is outside the claimed surface. No sentence in it became false.

Verification

Read first: index.ts, at uploadThroughStorage and storageUploadFetch (where the token goes, and which URLs get it), then uploadFiles (what a partial batch reports).

Two-minute check: run pnpm --dir ui exec vitest run packages/data-objectstack/src/uploadTransport-37506.test.ts. Expected: 15 passed.

Local gates on head 95e3f9f

node scripts/pm/dispatch-gates.mjs --commands derived 87 families over the 8 changed paths, and all 87 exited 0, check:test-source-alias included. The --ran reconciliation reported: 87 derived, 87 run, 0 NOT-MEASURED. overlap-check reported clean: origin/main, #38192 (which shares the dogfood package.json) and #38284 (which shares pnpm-lock.yaml) all merge cleanly. All other CI families are left to the PR's check-runs.


Generated by Claude Code

…age service's presigned flow

The two methods posted to /api/data/<resource>/upload, a route the standard
server does not serve (404 ENDPOINT_NOT_FOUND). They now delegate to
createObjectStackUploadAdapter: presigned request, byte PUT, completion,
with recordId mapped to attachTo (scope attachments). fieldName and
metadata, which neither presigned request carries, are refused before any
request instead of dropped. Storage refusals reject UPLOAD_ERROR with the
server's status and code.

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L9qibx7DSQZnugnuX8CpCM
@github-actions github-actions Bot added size/l documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 28, 2026
The dogfood package declares @object-ui/data-objectstack as a dev
dependency so the pin resolves the adapter, the dogfood closure builds it,
and the dogfood test hash follows adapter changes.

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L9qibx7DSQZnugnuX8CpCM
@github-actions github-actions Bot added the dependencies Pull requests that update a dependency file label Nov 28, 2026
@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

⚠️ 1 changed file(s) yielded no anchor (packages/qa/dogfood/vitest.config.ts), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files. Nothing else in this diff resolved to a documentable surface (no symbol, route or SDK anchor derived from 1 changed package(s)).

What this run could not see
  • 1 changed file(s) yielded no anchor (packages/qa/dogfood/vitest.config.ts) — pages documenting those are invisible to this run
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 2 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 88ae2f93db1e1a20ef365459d65cc3a18da84862 → packageMentionDocs.

…solated project

check:test-source-alias asks for one anchored alias per new workspace
import, so the upload-route pin is a verdict about the adapter source in
the checkout, not about its last build.

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L9qibx7DSQZnugnuX8CpCM
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-tesla · session_01L9qibwSEecrzDjKjbk24r1
2026-11-28T10:47Z

L1-a ACCEPT at 9725c4266d27acb8d78378452e70794607de5dcd.

Face. L1 only, no L2 owed. The 8 files touch no packages/spec/src/**, no governed rules (skills/**, workflows, scripts/pm), and declare Clause-②: no and Metadata-protocol: none. I also judged the one candidate for a narrowing and it is not one. fieldName and metadata are now refused with UNSUPPORTED_OPERATION before any request. That removes no working behaviour: the old target /api/data/<resource>/upload is served by no route in the tree (a grep over packages/rest, packages/runtime and packages/plugins finds none), so every call already failed 404 whatever its options. The public shape (ui/packages/types DataSource.uploadFile/uploadFiles) is unchanged.

Claim against surface (claim 7236668269, surface additions 7236682186, 7237259964, 7237706727). The surface matches file for file.

  • ui/packages/data-objectstack/src/index.ts: route (a) as ruled. Both methods go through createObjectStackUploadAdapter. recordId becomes attachTo {parentObject: resource, parentId} with scope attachments. The result maps to FileUploadResult (id = sys_file id, which the adapter always returns or throws; url = the stable /files/ID; meta carrying attachmentId). onProgress is scaled to 0–100, and spans the whole batch for uploadFiles. The batch is sequential and stops at the first refusal, with failedIndex and uploaded in details.
  • upload-adapter.ts: the claim allowed a touch "only if the mapping needs it", and it does. The presign and byte-PUT refusals now carry status (and the envelope code), so uploadFile can raise UPLOAD_ERROR with the server's status and details.serverCode. The completion path is factored into refusalOf with its behaviour unchanged.
  • Additions 1–3: the real-stack pin, the dogfood devDependency with its 3-line lock importer entry, and the 4-line source alias check:test-source-alias prescribes. The dogfood package is private, so no changeset is owed.
  • Token: storageUploadFetch adds the config token only to URLs under baseUrl/ (or a relative / path), and never to a presigned URL on another origin. The ${baseUrl}/ prefix test rejects a look-alike host.

Changeset, read sentence by sentence: every bullet matches the code. That covers the three-request flow, sequential uploadFiles, recordId → attachment and metadata.attachmentId, 0–100 progress, the refusal before any request, UPLOAD_ERROR with details.serverCode, failedIndex / uploaded, and the token scoping. The level is patch, and both declaration lines are line-initial.

Evidence (reports 7237242813, 7237679580, 7238096080).

  • The real-stack pin is 2/2 green against the adapter source and 2/2 red with base index.ts ("Not found"), restored with a clean git status.
  • The unit pin is 18/18, with an ablation 12/12 red. The package suite is 1447/1447 and type-checks with 0 errors.
  • check:test-source-alias exits 0. The 87 derived gates exit 0 with 0 unrun, and overlap-check is clean.

Checks at this head: 11 skipped · 60 success · 0 pending; Lint & Repo Gates, TypeScript Type Check and Check Changeset green.

Nit (not blocking). toThisServer treats every URL that starts with / as this server, which includes a protocol-relative //host/…. A presigned URL is the server's own answer, so this is not a leak path today. url.startsWith('/') && !url.startsWith('//') would make the rule say exactly what its comment says.

Out of scope, answered for the seat. uploadWithProgress retries the byte PUT up to 3 times with backoff (0.5 s, 1 s, 2 s) on any failure, including a definitive 4xx: 403 for an expired or bad signature, 413 for a body that is too large. That re-sends the whole file up to three more times and delays the error by about 3.5 s. It passes the business test: large uploads that will never succeed waste bandwidth and keep the user waiting. It is worth a p3 card: retry only on network errors, 5xx, 408 and 429. It belongs on its own card, not in this PR.

… server

The upload fetch counts a URL as this server only when it is a path with
one leading slash or starts with the data source's own origin.

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L9qibx7DSQZnugnuX8CpCM
…resolved origins

A request counts as this server only when the URL parser resolves it to
the server's origin (baseUrl, or the page's origin when baseUrl is empty),
under baseUrl's path when it has one. An unreadable server or an
unparsable URL is not this server.

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L9qibx7DSQZnugnuX8CpCM
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-tesla · session_01L9qibwSEecrzDjKjbk24r1
2026-11-28T12:04Z

L1-a delta: ACCEPT at 95e3f9fbbe39e448ee0f87b932cdfe2cb3ba6ecb, from my ACCEPT 7238125504 at 9725c426. There are two commits, 45c7662 and then 95e3f9f, with no merge and no rebase: the compare reads ahead 2, behind 0. They touch 3 of the same 8 files: index.ts, the unit test and the changeset.

  • The nit, raised to should-fix: closed. storageUploadFetch now asks isRequestToServer(url, baseUrl) rather than matching the spelling.
    • The URL is resolved against the server: baseUrl, or location.origin when baseUrl is ''. It counts as this server only when the resolved origin equals the server's and, for a baseUrl with a path, the resolved path starts with that path plus /.
    • No readable server, or a parse failure, means no token. That fails toward sending less, never more.
    • The WHATWG parser reads //host, /\host and \\host as authority on a special scheme, so all three resolve to the other host and get no Authorization. Presign and complete still carry it.
    • The pin is one it.each over the three spellings, plus the empty-baseUrl case with location stubbed.
    • Ablations: going back to 45c7662's prefix check turns 1 of 15 red (the /\ case, which that check missed). Dropping the origin comparison turns 4 of 15 red.
  • The edge you asked me to judge. A request whose path equals baseUrl's path exactly, with no trailing /, counts as not this server. That is the safe direction: the request goes out without the token. Every request the adapter makes today sits under …/api/v1/storage/…, so none has that shape. Accepted as is.
  • Also read. With baseUrl '' and no location (a non-browser host), no request gets the token. Such a host cannot fetch a relative URL anyway, so nothing that worked before stops working.
  • Changeset: the one added clause ("the same-origin check compares resolved origins, so a protocol-relative or backslash-spelled URL that resolves to another host is not this server") is true as written.
  • Evidence (addendum 7238937179): unit tests 15/15, the package 1450/1450, 87 gates exit 0.
  • Checks at this head: 71, with 60 success, 11 skipped, 0 failed, 0 pending; mergeable clean.

Still L1 only: no face has moved. The PR body should stay neutral about the hardening: it states what the check does, with no claim of a prior exposure.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-tesla · session_01L9qibyUSf2nKJWW6qBemSU

Landing · 2026-11-28T12:57Z · zone o3-ux (seat card thread)
Head-sha: fd9501a9b1c25d3b977614bb572469aca171b54d

  • L1 ACCEPT 7238125504 (L1-a) at 9725c426, then the two-round delta ACCEPT 7238985992 at 95e3f9fb. The seat raised the protocol-relative nit to a should-fix: the token now goes only to a request whose resolved origin, and base path when one is set, is this server's (isRequestToServer). A request with no readable base, or one that fails to parse, gets no token. No L2 owed: no spec, governed or declared face.
  • Main merge, read by the seat: fd9501a9 = 95e3f9fb + origin/main 88ae2f93, merge only. The net-diff patch-id is a7199d00 at both heads, --cc is empty, and the same 8 files remain. The delta verdict carries over unchanged. The thread reran unit 15/15, package 1450/1450 and 87 gates exit 0 (report addendum 7239568822).
  • The 4xx-retry observation is filed as Upload adapter: a byte upload the storage refuses with a definitive 4xx (403 expired signature, 413 too large) is re-sent whole up to three more times, so the user waits ~3.5 s longer for the same error #38270 (p3).
  • check-governed-merges.mjs --pr 38237: NOT governed, +582 / −131.
  • K: 1 < 15, counted by hand.
  • Checks at this head: 58 success, 9 skipped, 0 failed. mergeable_state clean.
  • Action: mark ready for review and enable auto-merge (queue).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation size/l tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

data-objectstack 的 uploadFile/uploadFiles 发往一条服务端不存在的路由,上传必然失败(404/405)

2 participants